package com.yuhf.util.db;

import lombok.extern.log4j.Log4j;

import java.sql.Connection;
import java.sql.SQLException;

@Log4j
public class TransactionManager {

    public void beginTransactionManager(){
        Connection connection=DBConnection.getConnection();
        try {
            connection.setAutoCommit(false);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public void commit(){
        Connection connection=DBConnection.getConnection();
        try {
            connection.commit();
            connection.setAutoCommit(true);
            DBConnection.closeConnection(connection);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public void rollback(){
        Connection connection=DBConnection.getConnection();
        try {
            connection.rollback();
            connection.setAutoCommit(true);
            DBConnection.closeConnection(connection);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
